package edu.ajax;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/jQueryAjax")
public class jQueryAjax extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.out.println("已接受到请求");
        Enumeration<String> parameterNames = request.getParameterNames();
        while (parameterNames.hasMoreElements()){
            String s = parameterNames.nextElement();
            String name = request.getParameter(s);
            System.out.println(s+"-->"+name);
        }

        Map<String, Object> map = new HashMap<>();
        map.put("data","这是数据");
        map.put("status",0);
        map.put("message","成功");

        String json = JSON.toJSONString(map);
        response.getWriter().write(json);
    }
}
